package cn.wang.open.sso.server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;

import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


@Configuration
public class Swagger2 {
	@Bean
	public Docket createRestApi() {
		Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("cn.wang.open.sso.server.controller");
		Predicate<RequestHandler> selector2 = RequestHandlerSelectors.basePackage("cn.wang.open.sso.client.controller");
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				.apis(Predicates.or(selector1,selector2))
				.paths(PathSelectors.any())
				.build();
	}
	
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("统一登录平台")
				.description("")
				.termsOfServiceUrl("")
				.version("1.0")
				.build();
	}
}